var mongoose = require('../common/db');

// 用户数据集
var user = new mongoose.Schema({
  username: String,
  password: String,
  userMail: String,
  userPhone: String,
  userAdmin: Boolean,
  userPower: Number,
  userStop: Boolean,
});

// 用户的查找方法
user.statics.findAll = function(callback) {
  this.find({}, callback);
};

// 使用用户名查找的方式
user.statics.findByUsername = function(name, callback) {
  this.find({ username: name }, callback);
};

// 登录匹配是不是拥有相同的用户名和密码，且账号没有被停用
user.statics.findUserLogin = function(name, password, callback) {
  this.find({ username: name, password: password }, callback);
};

// 验证有限、电话和用户名找到用户
user.statics.findUserPassword = function(name, mail, phone, callback) {
  this.find({ username: name, userMail: mail, userPhone: phone }, callback);
};

var userModel = mongoose.model('user', user);
module.exports = userModel;
